2020-2021 Sunseeker Telemetry and Lighting System
sd24_ex5_singleConversionSingleChannelInterrupt.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
33 // MSP430i20xx SD24 Example 05 - SD24, Single Conversion on a Single Channel, Use ISR
34 //
35 // Description: This program uses the SD24 module to perform a single
36 // conversion on a single channel. A SD24 interrupt occurs when a conversion
37 // has completed.
38 //
39 // Test by applying a voltage to the input channel and setting a breakpoint
40 // at the indicated line. Run program until it reaches the breakpoint, then use
41 // the debugger's watch window to view the conversion results.
42 //
43 // Results (upper 16 bits only) are stored in the variable "results"
44 //
45 // ACLK = 32kHz, MCLK = SMCLK = Calibrated DCO = 16.384MHz, SD_CLK = 1.024MHz
46 // * Ensure low_level_init.c is included when building/running this example *
47 //
48 // Notes: For minimum Vcc required for SD24 module - see datasheet
49 // 100nF cap btw Vref and AVss is recommended when using 1.2V ref
50 //
51 // MSP430i20xx
52 // -----------------
53 // /|\| |
54 // | | |
55 // --|RST |
56 // | |
57 // Vin1+ -->|A0.0+ VREF |---+
58 // Vin1- -->|A0.0- | |
59 // | | -+- 100nF
60 // | | -+-
61 // | | |
62 // | AVss |---+
63 //
64 // T. Witt
65 // Yang Lu
66 // Texas Instruments, Inc
67 // June 2014
68 // Built with Code Composer Studio v5.5
69 //******************************************************************************
70 #include "driverlib.h"
71 
72 uint16_t results; // SD24 Conversion Results
73 
74 void main(void) {
75  // Stop WDT
76  WDT_hold(WDT_BASE);
77 
78  // Internal ref
79  SD24_init(SD24_BASE, SD24_REF_INTERNAL);
80 
81  //Ch0 single mode
82  SD24_initConverterAdvancedParam param = {0};
83  param.converter = SD24_CONVERTER_0;
84  param.conversionMode = SD24_SINGLE_MODE;
85  param.groupEnable = SD24_NOT_GROUPED;
86  param.inputChannel = SD24_INPUT_CH_ANALOG;
87  param.dataFormat = SD24_DATA_FORMAT_2COMPLEMENT;
88  param.interruptDelay = SD24_FOURTH_SAMPLE_INTERRUPT;
89  param.oversampleRatio = SD24_OVERSAMPLE_256;
90  param.gain = SD24_GAIN_1;
91  SD24_initConverterAdvanced(SD24_BASE, &param);
92  SD24_enableInterrupt(SD24_BASE, SD24_CONVERTER_0, SD24_CONVERTER_INTERRUPT);
93 
94  // Delay ~200us for 1.2V ref to settle
95  __delay_cycles(3200);
96 
97  while(1) {
98  __no_operation(); // SET BREAKPOINT HERE
99  // Start conversion
100  SD24_startConverterConversion(SD24_BASE, SD24_CONVERTER_0);
101  // Enter LPM0 w/ interrupts
102  __bis_SR_register(LPM0_bits | GIE);
103  // For debugger
104  __no_operation();
105  }
106 }
107 
108 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
109 #pragma vector=SD24_VECTOR
110 __interrupt void SD24_ISR(void) {
111 #elif defined(__GNUC__)
112 void __attribute__ ((interrupt(SD24_VECTOR))) SD24_ISR (void) {
113 #else
114 #error Compiler not supported!
115 #endif
116  switch (__even_in_range(SD24IV,SD24IV_SD24MEM3)) {
117  case SD24IV_NONE: break;
118  case SD24IV_SD24OVIFG: break;
119  case SD24IV_SD24MEM0:
120  // Save CH0 results (clears IFG)
121  results = SD24_getHighWordResults(SD24_BASE, SD24_CONVERTER_0);
122  break;
123  case SD24IV_SD24MEM1: break;
124  case SD24IV_SD24MEM2: break;
125  case SD24IV_SD24MEM3: break;
126  default: break;
127  }
128  __bic_SR_register_on_exit(LPM0_bits); // Wake up from LPM0
129 }
MPU_initThreeSegmentsParam param
__no_operation()
__delay_cycles(500000)
__bic_SR_register_on_exit(LPM0_bits)